﻿Ext.define('app.prm.document.UploadTagFile',
{
    extend: 'Ext.window.Window',
    title: '上传文档',
    autoScroll: true,
    modal: true,
    width: 600,
    autoHeight: true,
    layout: 'fit',
    ProjectId: 0,
    TypeId: 0,
    initComponent: function () {
        var me = this;
        me.items = [this.getUploadForm()];
        me.buttons = [
            { text: '保存', scope: this, handler: me.onSave },
            { text: '关闭', handler: function () { me.close(); } }
        ]
        me.callParent();
    },
    getUploadForm: function () {
        var me = this;
        if (!this.uploadForm) {
            this.uploadForm = new Ext.form.Panel({
                defaultType: 'textfield',
                border: false,
                defaults: { anchor: '100%' },
                fieldDefaults: {
                    labelWidth: 90,
                    labelAlign: "right",
                    flex: 1,
                    margin: 6
                },
                items: [
                    {
                        xtype: 'filefield', fieldLabel: '文档附件', name: 'ProjectFile', buttonText: '浏览',
                        listeners: {
                            change: function (fld, value) {
                                var filename = value.replace(/(^.*(\\|\/))?/, "");
                                me.uploadForm.query("textfield[name=fileName]")[0].setValue(filename);
                            }
                        }
                    },
                    { fieldLabel: '文档名称', name: 'fileName' },
                    //{
                    //    xtype: 'textarea',
                    //    fieldLabel: '标签',
                    //    height: 150,
                    //    name: 'tags',
                    //    emptyText: '双击添加标签',
                    //    readOnly: true,
                    //    listeners: {
                    //        afterrender: function (el) {
                    //            el.getEl().on('dblclick', function () {
                    //                var win = Ext.create("app.prm.document.ChooseTag", { projectId: me.ProjectId, textValue: el.getValue() });
                    //                win.on("savesuccess", function (value) {
                    //                    el.setValue(value);
                    //                    win.close();
                    //                });
                    //                win.show();
                    //            });
                    //        }
                    //    }
                    //},
                    {
                        xtype: 'textarea',
                        name: 'note',
                        fieldLabel: '备注说明',
                        height: 200
                    }
                ]
            });
        }
        return this.uploadForm;
    },
    onSave: function () {
        var me = this;
        me.uploadForm.getForm().submit({
            submitEmptyText: false,
            url: '/prm/document/UploadAttachment',
            params: { ProjectId: me.ProjectId },
            success: function (form, response) {

                Ext.Msg.alert("系统提示", '上传成功');
                me.fireEvent("savesuccess");
            },
            failure: function () {
                Ext.Msg.alert("系统提示", '上传失败');
            }
        });
    }
});